/******************************************************
/	Cody Brenneman		12/20/2006
/	Skip Away prototype control in C
/
*******************************************************/

/*
#pragma config WDT = OFF
#pragma config OSC = INTIO2, LVP = OFF
#pragma config MCLRE = OFF
#pragma config FOSCSEL = 0x000001
 */

#include <p30f4013.h>
#include "Initializations.h"
#include "Delays.h"
#include "Interrupt Service Routines.h"
#include "Matrix_LCD.h"
//#include "Variables.h"

//testing the repository stuff...?

/* Setting the configuration registers  */
//_FBORPOR( PWRT_OFF & BORV45 & PBOR_OFF & MCLR_DIS )
_FBORPOR( PWRT_OFF & BORV45 & PBOR_OFF & MCLR_EN )
_FWDT(WDTPSB_1 & WDTPSA_1 & WDT_OFF)
_FOSC(FRC_PLL16)





/* Constants */
#define ON  1
#define OFF 0


#define SWITCHING_PIN       LATDbits.LATD2
#define BUTTON              PORTDbits.RD3



/* Function prototypes */
int main(void);
void InterruptHandlerHigh(void);
//void ConvertToNumber(unsigned char*);




/* High priority interrupt vector */
//#pragma code InterruptVectorHigh = 0x08
void InterruptVectorHigh (void)
{
    /*
  _asm
    goto InterruptHandlerHigh //jump to interrupt routine
  _endasm
     */
}


//--------------------------------------------------------------------------

/* Global variables */
unsigned char quarter_second = 0;
unsigned char one_minute_counter = 0;
unsigned char one_minute_flag = 0;
unsigned char minutes = 0;
unsigned char timer_flag = 0;
unsigned char current_addr = 0;
unsigned char current_y_addr;
unsigned char current_x_addr;




/* The main function should only be a base for
	calling other functions.  It will stay in an
	infinite loop */

//#pragma code main = 0x2A
/* make sure to start the main program in the proper
	area of memory! Code memory starts at 0x2A */


int main(void)
{
    unsigned char i = 0;
    unsigned char j = 0;

    oscillator_init();
    port_init();
    interrupt_init();
    timer2_init();


    tenth_seconds(2);

    LCD_init();



    LCD_write_instruction(LCD_YADDR(0), CHIP1);
    LCD_write_instruction(LCD_YADDR(0), CHIP2);
    LCD_write_instruction(LCD_XADDR(0), CHIP1);
    LCD_write_instruction(LCD_XADDR(0), CHIP2);

    
    while(1)
    {

        LCD_string2("testing this thing to see what happens ", BOTH_CHIPS);

        while(1);

        



        while(1)
        {
       
        for(i=0; i<8; i++)
        {
            LCD_write_instruction(LCD_XADDR(i), CHIP1);
            LCD_write_instruction(LCD_XADDR(i), CHIP2);
            for(j=0; j<32; j++)
            {
                LCD_write_data(0xFF, CHIP1);
                LCD_write_data(0x00, CHIP1);
                LCD_write_data(0x55, CHIP2);
                LCD_write_data(0xAA, CHIP2);
            }
        }

        milliseconds(50);

        for(i=0; i<8; i++)
        {
            LCD_write_instruction(LCD_XADDR(i), CHIP1);
            LCD_write_instruction(LCD_XADDR(i), CHIP2);
            for(j=0; j<32; j++)
            {
                LCD_write_data(0x00, CHIP1);
                LCD_write_data(0xFF, CHIP1);
                LCD_write_data(0xAA, CHIP2);
                LCD_write_data(0x55, CHIP2);
            }
        }

        milliseconds(50);


        SWITCHING_PIN = ! SWITCHING_PIN;
        }

        
    }

    return(0);
}




//--------------------------------------------------------------------------
//		Interrupt handling
//--------------------------------------------------------------------------


/* High priority interrupt routine */

//#pragma code
//#pragma interrupt InterruptHandlerHigh

/* Handles all high priority interrupts
	so check which interrupt has occurred
	and then service it */
void InterruptHandlerHigh(void)
{
/*
    if (INTCONbits.TMR0IF)
    {
		INTCONbits.TMR0IF = 0;		//reset it
		Timer0ISR();
	}

	if(PIR1bits.TMR1IF)
	{
		PIR1bits.TMR1IF = 0;
		Timer1ISR();
	}


	if(INTCONbits.INT0IF)
	{
		LED = 1;					//turn on LED
		while(!SLEEP_BUTTON);
		LED = 0;					//until sleep button is released
		INTCONbits.INT0IF = 0;		//clear the interrupt flag
		INTCON3bits.INT1IF = 0;
		T0CONbits.TMR0ON = 1;		//Start timer 0
		timer_flag = 1;				//So i know it's timing something now
	}
*/
}


